package com.yanqu.road.entity.activity.feast.data;

import com.yanqu.road.entity.enums.feast.eFeastType;

import java.io.Serializable;
import java.util.Map;

public class FeastBattleData implements Serializable {
    private int type;           // 1:玩家2：npc
    private int id;             // 序号
    private int npcId;          // npc配置id
    private long hp;             // 血量
    private long maxHp;          // 最大血量
    private long atk;            // 攻击力
    private int critRatio;      // 暴击率，基数1000

    // TODO 需求修改暂时去掉
    private int backRatio;      // 反击率，基数1000
    private int stunRatio;     // 晕眩率，基数1000
    private int defense;        // 防御值

    private int hitRatio;       // 命中率，基数1000
    private int tenacity;       // 坚韧度，基数1000

    private int attackSpeed;    // 攻速，基数1000，单位秒
    private int suckRatio;      // 吸血，基数1000
    private int dodgeRatio;     // 闪避，基数1000
    private int anger;          // 怒气值
    private int atkTime;        // 攻击时间
    private int skillId;        // 技能id
    private long skillAtk;      // 技能攻击力
    private int stunFinishTime; // 晕眩结束时间
    private int lastCalcAngerTime;       // 上一次恢复怒气时间

    private int nextAtk;

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getNpcId() {
        return npcId;
    }

    public void setNpcId(int npcId) {
        this.npcId = npcId;
    }

    public long getHp() {
        return hp;
    }

    public void setHp(long hp) {
        if (hp > maxHp) {
            hp = maxHp;
        }
        this.hp = hp;
    }

    public long getMaxHp() {
        return maxHp;
    }

    public void setMaxHp(long maxHp) {
        this.maxHp = maxHp;
    }

    public long getAtk() {
        return atk;
    }

    public void setAtk(long atk) {
        this.atk = atk;
    }

    public int getBackRatio() {
        return backRatio;
    }

    public void setBackRatio(int backRatio) {
        this.backRatio = backRatio;
    }

    public int getCritRatio() {
        return critRatio;
    }

    public void setCritRatio(int critRatio) {
        this.critRatio = critRatio;
    }

    public int getStunRatio() {
        return stunRatio;
    }

    public void setStunRatio(int stunRatio) {
        this.stunRatio = stunRatio;
    }

    public int getAttackSpeed() {
        return attackSpeed;
    }

    public void setAttackSpeed(int attackSpeed) {
        this.attackSpeed = attackSpeed;
    }

    public int getSuckRatio() {
        return suckRatio;
    }

    public void setSuckRatio(int suckRatio) {
        this.suckRatio = suckRatio;
    }

    public int getDodgeRatio() {
        return dodgeRatio;
    }

    public void setDodgeRatio(int dodgeRatio) {
        this.dodgeRatio = dodgeRatio;
    }

    public int getDefense() {
        return defense;
    }

    public void setDefense(int defense) {
        this.defense = defense;
    }

    public int getAnger() {
        return anger;
    }

    public void setAnger(int anger) {
        this.anger = anger;
    }

    public int getAtkTime() {
        return atkTime;
    }

    public void setAtkTime(int atkTime) {
        if (atkTime == 0) {
            //atkTime = getCDMs();
        }
        this.atkTime = atkTime;
        this.nextAtk++;
    }

    public FeastBattleData(int type, int id, int npcId, Map<Integer, Long> attrMap, int skillId, long skillAtk) {
        this.type = type;
        this.npcId = npcId;
        this.id = id;
        this.hp = attrMap.getOrDefault(eFeastType.BattleAttrType.Hp.getValue(), 0L);
        this.maxHp = this.hp;
        this.atk = attrMap.getOrDefault(eFeastType.BattleAttrType.Atk.getValue(), 0L);
        this.critRatio = attrMap.getOrDefault(eFeastType.BattleAttrType.CritRatio.getValue(), 0L).intValue();
        this.tenacity = attrMap.getOrDefault(eFeastType.BattleAttrType.TenacityRatio.getValue(),0L).intValue();
        this.hitRatio = attrMap.getOrDefault(eFeastType.BattleAttrType.HitRatio.getValue(),0L).intValue();
        this.backRatio = 0;
        this.stunRatio = 0;
        this.defense = 0;
        this.attackSpeed = attrMap.getOrDefault(eFeastType.BattleAttrType.AtkSpeed.getValue(), 0L).intValue();
        this.suckRatio = attrMap.getOrDefault(eFeastType.BattleAttrType.SuckRatio.getValue(), 0L).intValue();
        this.dodgeRatio = attrMap.getOrDefault(eFeastType.BattleAttrType.DodgeRatio.getValue(), 0L).intValue();
        this.anger = 0;
        this.atkTime = 0;
        this.skillId = skillId;
        this.skillAtk = skillAtk;
    }
    // 获取攻击CD(毫秒)
    public int getCDMs() {
        return (int)Math.ceil((double) 1000*1000/attackSpeed);
    }

    // 获取下一次的攻击时间
    public int nextAtkTime() {
        if (atkTime == 0 && nextAtk == 0) {
            return atkTime;
        }
        return atkTime + getCDMs();
    }

    public int getSkillId() {
        return skillId;
    }

    public void setSkillId(int skillId) {
        this.skillId = skillId;
    }

    public int getStunFinishTime() {
        return stunFinishTime;
    }

    public void setStunFinishTime(int stunFinishTime) {
        this.stunFinishTime = stunFinishTime;
    }

    public long getSkillAtk() {
        return skillAtk;
    }

    public void setSkillAtk(long skillAtk) {
        this.skillAtk = skillAtk;
    }

    public int getLastCalcAngerTime() {
        return lastCalcAngerTime;
    }

    public void setLastCalcAngerTime(int lastCalcAngerTime) {
        this.lastCalcAngerTime = lastCalcAngerTime;
    }

    public int getHitRatio() {
        return hitRatio;
    }

    public void setHitRatio(int hitRatio) {
        this.hitRatio = hitRatio;
    }

    public int getTenacity() {
        return tenacity;
    }

    public void setTenacity(int tenacity) {
        this.tenacity = tenacity;
    }
}
